package com.ruoyi.lhb.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lhb.domain.Expatriaterecords;
import com.ruoyi.lhb.service.IExpatriaterecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外派记录Controller
 *
 * @author lhb
 * @date 2022-09-28
 */
@RestController
@RequestMapping("/lhb/expatriaterecords")
public class ExpatriaterecordsController extends BaseController
{
    @Autowired
    private IExpatriaterecordsService expatriaterecordsService;

    /**
     * 查询外派记录列表
     */
    @PreAuthorize("@ss.hasPermi('lhb:expatriaterecords:list')")
    @GetMapping("/list")
    public TableDataInfo list(Expatriaterecords expatriaterecords)
    {
        startPage();
        List<Expatriaterecords> list = expatriaterecordsService.selectExpatriaterecordsList(expatriaterecords);
        return getDataTable(list);
    }

    /**
     * 导出外派记录列表
     */
    @PreAuthorize("@ss.hasPermi('lhb:expatriaterecords:export')")
    @Log(title = "外派记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Expatriaterecords expatriaterecords)
    {
        List<Expatriaterecords> list = expatriaterecordsService.selectExpatriaterecordsList(expatriaterecords);
        ExcelUtil<Expatriaterecords> util = new ExcelUtil<Expatriaterecords>(Expatriaterecords.class);
        util.exportExcel(response, list, "外派记录数据");
    }

    /**
     * 获取外派记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('lhb:expatriaterecords:query')")
    @GetMapping(value = "/{expatriateid}")
    public AjaxResult getInfo(@PathVariable("expatriateid") Long expatriateid)
    {
        return AjaxResult.success(expatriaterecordsService.selectExpatriaterecordsByExpatriateid(expatriateid));
    }

    /**
     * 新增外派记录
     */
    @PreAuthorize("@ss.hasPermi('lhb:expatriaterecords:add')")
    @Log(title = "外派记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Expatriaterecords expatriaterecords)
    {
        return toAjax(expatriaterecordsService.insertExpatriaterecords(expatriaterecords));
    }

    /**
     * 修改外派记录
     */
    @PreAuthorize("@ss.hasPermi('lhb:expatriaterecords:edit')")
    @Log(title = "外派记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Expatriaterecords expatriaterecords)
    {
        return toAjax(expatriaterecordsService.updateExpatriaterecords(expatriaterecords));
    }

    /**
     * 删除外派记录
     */
    @PreAuthorize("@ss.hasPermi('lhb:expatriaterecords:remove')")
    @Log(title = "外派记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{expatriateids}")
    public AjaxResult remove(@PathVariable Long[] expatriateids)
    {
        return toAjax(expatriaterecordsService.deleteExpatriaterecordsByExpatriateids(expatriateids));
    }
}
